<div class="grid_15" id="newStyles">
<div class="cancelNavigation">[ <a href="<?php print( $this->returnUrl ? $this->returnUrl : (Account_Rd::atLeastStaff() ? './?cmd=manageClasses' : './?cmd=viewCourseList')); ?>">Cancel</a> ]</div>

<?php
//add the origin cmd and the next cmd to hidden fields
//this will tell the manager where to return in case of a dupe
//and where to proceed if class is created successfully
$hiddenFields = $this->hidden ? $this->hidden : array();
$cmd = $this->cmd ? $this->cmd : 'createClass';
if ($this->successCmd) {
	$hiddenFields['successCmd'] = $this->successCmd;
}

$instructorErrorClass = Rd_Layout::hasMessage('instructorMatchError') ? ' error' : '';
$departmentErrorClass = Rd_Layout::hasMessage('departmentMatchError') ? ' error' : '';
$termErrorClass = Rd_Layout::hasMessage('termMatchError') ? ' error' : '';
$courseNumberErrorClass = $this->submitted && !$this->courseNumber ? ' error' : '';
$sectionErrorClass = $this->submitted && !$this->section ? ' error' : '';
$enrollmentErrorClass = $this->submitted && !$this->enrollment ? ' error' : '';
$courseNameErrorClass = $this->submitted && !$this->courseName ? ' error' : '';



?>
		<script language="JavaScript">
$(document).ready(function() {
		$('#dynamicDepartmentPicker').show();
		$('#staticDepartmentPicker').hide();
		$('#departmentSearchField').autocomplete({
			source : rd.getBaseUrl() + 'json/autocomplete/dept/',
			minLength : 2,
			select : function(event,ui) {
				this.value = ui.item.label;
				var oldSelectedOption = $('[name="department"] option[selected="selected"]');
				oldSelectedOption.attr('selected', false);
				var selectedOption = $('[name="department"] option[value="' + ui.item.value + '"]');
				selectedOption.attr('selected', true);
				//this.form.submit();
				return false;
			}
		});
		$('#instructorSearchField').autocomplete({
			source : rd.getBaseUrl() + 'json/autocomplete/instructororproxy/',
			minLength : 2,
			select : function(event,ui) {
				this.value = ui.item.label;
				$('#searchInstructorResult').val(ui.item.value);
				//this.form.submit();
				return false;
			}
		});
});
		</script>
<h2 class="formHeader grid_7">CLASS DETAILS</h2>
<form class="bordered clearing basicPadding bottomMargin" name="frmClass" action="./?cmd=<?php print($cmd);?>" method="post" onSubmit="return validate(this);">	
	<input type="hidden" name="cmd" value="<?php print($cmd); ?>" />			
	<?php $this->getDisplayer()->displayHiddenFields($hiddenFields); ?>
<?php	if($this->msg){ ?>
		<p class="policyNotice"><?php print($this->msg); ?></p>
<?php	} ?>
		<label class="blockLabel bottomHalfMargin"><span class="labelTex<?php print($departmentErrorClass); ?>t">Department:</span>
			<span id="staticDepartmentPicker"><?php $this->getDisplayer()->displayDepartmentSelect($this->department);?></span>
			<span class="hidden" id="dynamicDepartmentPicker"><input type="text" name="searchDepartment" id="departmentSearchField" value="<?php print($this->searchDepartment); ?>" size="40" />
			<span class="supplementText">Course Department Name or Abbreviation</span></span>
			<?php if ($departmentErrorClass) { ?>	
				<span class="formAlertMessage supplementText failedText"><?php print(Rd_Layout::getMessage('departmentMatchError'));?></span>
			<?php } ?>
		</label>
		<label class="blockLabel bottomHalfMargin"><span class="labelTextLong<?php print($courseNumberErrorClass); ?>">Course Number:</span>
			<input name="courseNumber" type="text" id="courseNumber" size="5" value="<?php print($this->courseNumber); ?>" />
			<?php if ($courseNumberErrorClass) { ?>	
				<span class="formAlertMessage supplementText failedText">This field is required.</span>
			<?php } ?>
		</label>
		<label class="blockLabel bottomHalfMargin"><span class="labelTextLong<?php print($sectionErrorClass); ?>">Section:</span>
			<input name="section" type="text" id="section" size="5" value="<?php print($this->section); ?>" />
			<?php if ($sectionErrorClass) { ?>	
				<span class="formAlertMessage supplementText failedText">This field is required.</span>
			<?php } ?>
		</label>
		<label class="blockLabel bottomHalfMargin"><span class="labelTextLong<?php print($courseNameErrorClass); ?>">Course Name:</span>
			<input name="courseName" type="text" id="courseName" size="50" value="<?php print($this->courseName); ?>" />
			<?php if ($courseNameErrorClass) { ?>	
				<span class="formAlertMessage supplementText failedText">This field is required.</span>
			<?php } ?>
		</label>
		<label class="blockLabel bottomHalfMargin"><span class="labelTextLong<?php print($termErrorClass); ?>">Term:</span>
		
<?php
		//allow staff or above to edit start/end dates
		$showDates = Account_Rd::atLeastStaff();
	
		//show term selection
		$this->getDisplayer()->displayTermSelect($this->term, $showDates);
?>
		<?php if ($termErrorClass) { ?>	
			<span class="formAlertMessage supplementText failedText"><?php print(Rd_Layout::getMessage('termMatchError'));?></span>
		<?php } ?>
		</label>
		<label class="blockLabel bottomHalfMargin"><span class="labelText<?php print($enrollmentErrorClass); ?>">Enrollment:</span>
			<?php $this->getDisplayer()->displayEnrollmentSelect($this->enrollment, TRUE); ?>
			<?php if ($enrollmentErrorClass) { ?>	
				<span class="formAlertMessage supplementText failedText">This field is required.</span>
			<?php } ?>
		</label>
		
<?php	if(Account_Rd::atLeastStaff()){ //show instructor lookup for staff ?>
		<label class="blockLabel topDoubleMargin bottomHalfMargin"><span class="labelText<?php print($instructorErrorClass); ?>">Instructor:</span>
			<input type="text" name="searchInstructor" id="instructorSearchField" value="<?php print($this->searchInstructor); ?>" size="40" />
			<span class="supplementText">Name or Username</span>
			<input type="hidden" name="searchInstructorResult" id="searchInstructorResult" value="<?php print($this->instructor); ?>"/>
			<?php if ($instructorErrorClass) { ?>	
				<span class="formAlertMessage supplementText failedText"><?php print(Rd_Layout::getMessage('instructorMatchError'));?></span>
			<?php } ?>
		</label>
<?php	 } else {	//add instructor as hidden field ?>

						<input type="hidden" id="selected_instr" name="selected_instr" value="<?php print(Account_Rd::getId()); ?>" />

<?php	} ?>

		
			<input class="marginCenter" type="submit" name="Submit" value="Create Course"/> <!-- onClick="this.form.cmd.value='createNewClass';javascript:return validate(document.forms.frmClass);"> --> 

</form>